package com.guojiaming.shop.service;

import com.guojiaming.shop.bean.Book;
import com.guojiaming.shop.dao.BookMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @author vivo
 */
@Service
@Transactional(rollbackFor = {Exception.class})
public class BookService {
    @Resource
    private BookMapper bookMapper;

    public Book read(Integer bookId, Integer id, Integer type) {
        if (id == null) {
            return bookMapper.findFirstBook(bookId);
        }
        Book book;
        if (type == 0) {
            book = bookMapper.findNextPage(id, bookId);
        } else {
            book = bookMapper.previousPage(id, bookId);
        }

        if (book == null) {
            book = new Book();
            book.setBookContent("没有更多了");
            book.setBookId(-100);
            book.setTitle("没有更多了");
        }
        return book;
    }
}
